/**
 * 添加或者修改页面
 */
var FlowServiceInfoDlg = {
    data: {
        serviceId: "",
        serviceName: "",
        bgUrl: "",
        tags: "",
        notes: "",
        payNotes: "",
        process: "",
        points: ""
    }
};

layui.use(['form', 'admin', 'ax','laydate','upload','formSelects','inputTags'], function () {
    var $ = layui.jquery;
    var $ax = layui.ax;
    var form = layui.form;
    var admin = layui.admin;
    var inputTags = layui.inputTags;

    var tags = inputTags.render({
        elem:'#inputTags',
        content:[],//是否开启获取所有数据的按钮
        done: function(value){ //回车后的回调
            console.log(value);
            console.log(tags);
        },//默认标签
        aldaBtn: true,//是否开启获取所有数据的按钮
    });

    //普通图片上传
    var upload = layui.upload;
    upload.render({
        elem: '#bgUrlBtn'
        ,url: Feng.ctxPath + '/system/upload' //改成您自己的上传接口
        ,before: function(obj){
            //预读本地文件示例，不支持ie8
            obj.preview(function(index, file, result){
                $('#filePreview1').attr('src', result); //图片链接（base64）
            });
        }
        ,done: function(res){
            $("#bgUrl").val("/upload/"+res.data.fileName);
            Feng.success(res.message);
        }
        ,error: function(){
            Feng.error("上传文件失败！");
        }
    });

    upload.render({
        elem: '#processBtn'
        ,url: Feng.ctxPath + '/system/upload' //改成您自己的上传接口
        ,before: function(obj){
            //预读本地文件示例，不支持ie8
            obj.preview(function(index, file, result){
                $('#filePreview2').attr('src', result); //图片链接（base64）
            });
        }
        ,done: function(res){
            $("#process").val("/upload/"+res.data.fileName);
            Feng.success(res.message);
        }
        ,error: function(){
            Feng.error("上传文件失败！");
        }
    });





















    //表单提交事件
    form.on('submit(btnSubmit)', function (data) {
        data.field.notes = encodeURIComponent(data.field.notes);
        data.field.payNotes = encodeURIComponent(data.field.payNotes);
        data.field.points = encodeURIComponent(data.field.points);
        var tagstr = "";
        if(tags.config.content && tags.config.content.length > 0){
            for (var i = 0;i<tags.config.content.length;i++){
                if(i == 0){
                    tagstr += tags.config.content[i];
                }else {
                    tagstr += ","+tags.config.content[i];
                }
            }
        }
        data.field.tags = tagstr;
        var ajax = new $ax(Feng.ctxPath + "/flowService/addItem", function (data) {
            Feng.success("添加成功！");
            //传给上个页面，刷新table用
            admin.putTempData('formOk', true);
            //关掉对话框
            admin.closeThisDialog();
        }, function (data) {
            Feng.error("添加失败！" + data.responseJSON.message)
        });
        ajax.set(data.field);
        ajax.start();

        return false;
    });


    $(document).keyup(function(event){
        return false;
    });
});